import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:video_setting/pages/utils/numerical_extension.dart';

class LoadingWidget extends Dialog {
  final String? text;
  final Color bgColor;
  final Color? loadingColor;
  final TextStyle? textStyle;

  const LoadingWidget({Key? key, this.text = '加载中...', this.bgColor = Colors.transparent, this.loadingColor, this.textStyle}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return getLoadingWidget(context: context, text: text, bgColor: bgColor, textStyle: textStyle);
  }

  Widget getLoadingWidget({required BuildContext context, String? text, Color? bgColor, TextStyle? textStyle}) {
    return Material(

        /// 透明
        type: MaterialType.transparency,

        /// 保证控件居中显示
        child: Center(
            child: SizedBox(
                width: 80.px,
                height: 80.px,
                child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[
                  Center(
                      child: SpinKitCircle(
                    color: loadingColor,
                    size: 30.px,
                    itemBuilder: (BuildContext context, int index) {
                      return Container(
                        // loading的形状
                        decoration: BoxDecoration(
                          borderRadius: const BorderRadius.all(Radius.circular(15)),
                          color: index.isEven ? Colors.white : Colors.white,
                        ),
                      );
                    },
                  )),
                ]))));
  }
}
